package core;

import java.util.logging.Level;
import java.util.logging.FileHandler;
import java.util.logging.LogManager;
import java.util.logging.Logger;

//Universal logger class
public class Log
{
	private static Logger logger = Logger.getLogger(Log.class.getName());

//	BufferedWriter br = new BufferedWriter(new PrintWriter(System.out));
//	private String NEW_LINE = "\n";

	public static void init() {
		try {
			LogManager lm = LogManager.getLogManager();
			FileHandler fh = new FileHandler("log_test.xml");

			lm.addLogger(logger);

			logger.addHandler(fh);
		}
		catch (Exception e) {
			System.out.println("Exception thrown: " + e);
			e.printStackTrace();
		}
	}

	public static void debug(String s) {
		logger.log(Level.INFO, s);
	}

//	public void enter(String s) {
//		try {
//			br.write(s + NEW_LINE);
//		} catch (IOException e) {
//			error(e.getMessage());
//		}
//	}
//
//	public void exit(String s) {
//		try {
//			br.write(s + NEW_LINE);
//		} catch (IOException e) {
//			error(e.getMessage());
//		}
//	}

	public static void warn(String s) {
		logger.log(Level.WARNING,s);
	}

	public static void error(String s) {
		logger.log(Level.SEVERE, s);
	}

	public static void setLogLevel(Level newLevel) {
		logger.setLevel(newLevel);
	}
}